<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>菜单列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/style.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/my.css/}" media="all">

</head>
<body class="body">

<script type="text/html" id="topOperate">
    <div class="my-btn-box layui-form">
      <span class="fl">
          <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="allDel"><i class="layui-icon layui-icon-delete"></i>全部删除</button>
          <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="chooseDel"><i class="layui-icon layui-icon-delete"></i>选中删除</button>
      </span>

    </div>
</script>

<fieldset class="layui-elem-field layui-field-title">
    <legend>清除条件选择</legend>
    <div class="layui-field-box layui-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">余额低于(元)</label>
                <div class="layui-input-inline">
                    <input type="text" name="balanceMoney" lay-verify="number" autocomplete="off" style="width: 100px;" placeholder="元"  class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">未登录天数</label>
                <div class="layui-input-inline">
                    <input type="text" name="notLoginDay"  lay-verify="number"  value="60" placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">用户ID</label>
                <div class="layui-input-inline">
                    <input type="text" name="userId"  lay-verify="number"   placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">易聊号</label>
                <div class="layui-input-inline">
                    <input type="text" name="appId"    placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">手机号</label>
                <div class="layui-input-inline">
                    <input type="text" name="tel" id="date" lay-verify="number"   placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

    </div>
</fieldset>

<div class="my-btn-box layui-form">
    <span class="fr">
        <button class="layui-btn layui-btn-sm" id="search"><i class="layui-icon">&#xe615;</i></button>
    </span>
</div>

<!-- 表格 -->
<div id="dateTable" lay-filter="event"></div>
<div class="height50"></div>
<script th:src="@{/js/layui/layui.js}"></script>
<script th:src="@{/js/fyn/index.js}"></script>
<script th:src="@{/js/fyn/my.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_comm.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_table.js}"></script>
<script type="text/javascript" th:inline="javascript">

    // layui方法
    layui.use(['table', 'form', 'laypage', 'layer', 'vip_table'], function () {

        // 操作对象
        var form = layui.form
            , table = layui.table
            , layer = layui.layer
            , vipTable = layui.vip_table
            , $ = layui.jquery;

        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , height: "full"    //容器高度
            , skin: 'line'
            , even: 'true'
            , cols: [[                  //标题栏
                {
                    field: 'menu.id', title: 'ID', width: '7%', sort: true, align: 'center',type:'checkbox'

                }
                , {
                    field: 'menu.name', title: '头像', align: 'center', width: '10%', templet: function (d) {
                        return d.avatar == null ? "" : ("<img src='" + d.avatar + "'/>");
                    }
                }
                , {
                    field: 'pName', title: '昵称', width: '10%', align: 'center', templet: function (d) {
                        return d.nick;
                    }
                }

                , {
                    field: 'pName', title: '手机号', width: '10%', align: 'center', templet: function (d) {
                        return d.mobile;
                    }
                }

                , {
                    field: 'menu.status', title: '状态', width: "10%", event: 'updateS', templet: function (d) {
                        return "<input lay-filter='status' disabled  type='checkbox' name='status'" + (d.status == 0 ? "checked" : "") + " lay-skin=\"switch\" lay-text=\"开启|冻结\" class=\"status\">";
                        //return d.user.status == 0 ? '<i class="layui-icon" style="font-size: 20px; color: green;">&#xe605;</i>' : "<i class=\"layui-icon\" style=\"font-size: 20px; color: green;\">&#x1006;</i>";
                    }
                }
                , {
                    field: 'pName', title: '平台', width: '10%', align: 'center', templet: function (d) {
                        if(d.platform==0){
                            return "苹果";
                        }else if( d.platform==1){
                            return "安卓";
                        }else if (d.platform==2){
                            return "web";
                        }else {
                            return "";
                        }
                    }
                }
                , {
                    field: 'pName', title: '微信ID', width: '10%', align: 'center', templet: function (d) {
                        return d.appid == null ? '' : d.appid;
                    }
                }
                , {
                    field: 'pName', title: '唯一码', width: '10%', align: 'center', templet: function (d) {
                        return d.ucode == null ? '' : d.ucode;
                    }
                }

                , {
                    field: 'user.ctime',
                    align: 'center',
                    title: '创建时间',
                    sort: true,
                    width: "15%",
                    templet: function (d) {
                        return new Date(d.ctime).Format("yyyy-MM-dd hh:mm:ss");
                    }
                }


                , {title: '操作', align: 'center', toolbar: '#barOption'} //这里的toolbar值是模板元素的选择器
            ]]
            , id: 'dataCheck'
            , url: [[${basePath}]] + '/member/clean/list'
            , method: 'get'
            , page: true
            , limits: [10, 30, 60, 90, 150, 300]
            , toolbar: '#topOperate'
            , limit: 10 //默认采用0
            , loading: true
            // , where: getJson()
            , done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                $("td[data-field='content']").each(function () {
                    $(this).find(".layui-table-cell").removeClass('layui-table-cell');
                });


            }
        });


        //头工具栏事件
        table.on('toolbar(event)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;

            switch (obj.event) {
                case 'allDel':
                    layer.confirm("确定清除列表全部用户数据?", {
                        icon: 3,
                        title: '提示'
                    }, function (index) {
                        var ss=getJson().where;
                        ss.type=0;
                        $.ajax({
                            type: "post",
                            url: [[${basePath}]] + "/member/clean/user",
                            data: ss,
                            success: function (res) {
                                if (res.success) {
                                    layer.msg("清除完成", {icon: 1}, 500);

                                    layer.close(index);

                                    tableIns.reload();
                                }
                            }
                        });


                    });
                    break;
                case 'chooseDel':
                    var ids = [];
                    layui.each(data, function (i, val) {
                        ids.push(val.id);
                    });
                    if (ids.length === 0) {
                        layer.msg("请选择删除的用户！", {icon: 7, time: 1500});
                        return;
                    }
                    layer.confirm("确定清除选中用户数据?", {
                        icon: 3,
                        title: '提示'
                    }, function (index) {
                        var ss=getJson().where;
                        ss.type=1;
                        ss.ids=ids.join(",");
                        $.ajax({
                            type: "post",
                            url: [[${basePath}]] + "/member/clean/user",
                            data: ss,
                            success: function (res) {
                                if (res.success) {
                                    layer.msg("清除完成", {icon: 1}, 500);

                                    layer.close(index);

                                    tableIns.reload();
                                }
                            }
                        });


                    });
                    break;
            }
        });

        table.on('tool(event)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                layer.open({
                    type: 2,
                    title: '用户详情',
                    shadeClose: true,
                    shade: 0.2,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['650px', '550px'],
                    content: [[${basePath}]] + '/member/detail?id=' + data.id
                });

            }

            //清除登录token
            if (obj.event === 'delete') {

                layer.confirm("确定删除该用户？", {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/member/clean/login/status",
                        data: {id: data.id},
                        success: function (res) {
                            if (res.success) {
                                layer.msg("清除完成", {icon: 1}, 500);

                                layer.close(index);

                                tableIns.reload();
                            }
                        }
                    });


                });

            }

            if (obj.event === 'updateS') {

                layer.confirm("确定" + (data.status == 0 ? "冻结" : "开启") + "用户状态?", {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/member/status/update",
                        data: {id: data.id, status: data.status == 0 ? 1 : 0},
                        success: function (res) {
                            if (res.success) {
                                layer.msg("操作完成", {icon: 1}, 500);

                                layer.close(index);

                                tableIns.reload();
                            }
                        }
                    });


                }, function (index) {


                });
            }

        });


        var status = 0;
        form.on('switch(status)', function (data) {
            if (!data.elem.checked) {
                status = 1;
            } else {
                status = 0;
            }

            $("#search").click();

        });


        function getJson() {

            return {
                where: {
                    balanceMoney: $("input[name='balanceMoney']").val(),
                    userId: $("input[name='userId']").val(),
                    tel: $("input[name='tel']").val()
                    , notLoginDay: $("input[name='notLoginDay']").val()
                    , ucode: $("input[name='ucode']").val()
                    , appId: $("input[name='appId']").val()
                }
            };
        }

        $("#search").click(function () {
            tableIns.reload({
                where: {
                    balanceMoney: $("input[name='balanceMoney']").val(),
                    userId: $("input[name='userId']").val(),
                    tel: $("input[name='tel']").val()
                    , notLoginDay: $("input[name='notLoginDay']").val()
                    , ucode: $("input[name='ucode']").val()
                    , appId: $("input[name='appId']").val()
                },
                page: {
                    curr: 1
                }
            });
        })


    });
</script>
<!-- 表格操作按钮集 -->
<script type="text/html" id="barOption">
    <!--<i class="layui-icon layui-icon-file" style="cursor: pointer" lay-event="edit"></i>-->

</script>
</body>
</html>